/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package fr.ove.openmath.jome.ctrl.amto;

/**
 *
 * @author Mr.Sam
 */
import fr.ove.openmath.jome.ctrl.linear.events.LinearParserEvent;
import fr.ove.openmath.jome.ctrl.amto.Function;

/**
* The abstract math tree object of the definite integral
*
* @author © 2000 DIRAT Laurent
* @version 1.0  23/02/2000
*/
public class DefiniteIntegral extends Function {
    /**
    * The constructor.
    */
    public DefiniteIntegral() {
        super("defint");
    }
    
    /**
    * "Flushes" the object as a sequence of events for the building of the model
    */
    public void flush() {
        LinearParserEvent linearParserEvent = new LinearParserEvent(getEventSource());
        // Le format est un interval, suivit de la lambda expression de la fonction intégrée
        
        // The opening
        linearParserEvent.setToken(opening, param);
        fireLinearParserEvent(linearParserEvent);
        
        
        AbstractMathTreeObject interval = (AbstractMathTreeObject) getChild(0);
        AbstractMathTreeObject lambda = (AbstractMathTreeObject) getChild(1);
        
        // On envoie l'objet de la lambda expression, i.e. ce qui est dérivé
        int nbChildren = lambda.getNbChildren();
        int count = nbChildren - 1;
        flushChild(lambda.getChild(count), count);
        linearParserEvent.setToken(token, null);
        fireLinearParserEvent(linearParserEvent);
        
        // On envoie la variable liée, pour servir de variable d'intégration
        flushChild(lambda.getChild(0), 0);
        linearParserEvent.setToken(token, null);
        fireLinearParserEvent(linearParserEvent);
        
        // On envoie maintenant les bornes de l'intervalle
        flushChild(interval.getChild(0), 0);
        linearParserEvent.setToken(token, null);
        fireLinearParserEvent(linearParserEvent);
        flushChild(interval.getChild(1), 1);
        
        // The closing
        linearParserEvent.setToken(closing, null);
        fireLinearParserEvent(linearParserEvent);
    }
}